package com.eshop.product.controller;

import com.eshop.product.model.Product;
import com.eshop.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName CategoryController
 * @Description
 * @Author 47980
 * @Date 2020/5/17 16:18
 * @Version V_1.0
 **/
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("/add")
    public String add (Product product, String operationType) {
        try {
            productService.add(product, operationType);
        } catch (Exception e) {
            return e.getMessage();
        }
        return "success";

    }

    @GetMapping("/update")
    public String update (Product product, String operationType) {
        try {
            productService.update(product, operationType);
        } catch (Exception e) {
            return e.getMessage();
        }
        return "success";
    }

    @GetMapping("/delete")
    public String delete (Long id, String operationType) {
        try {
            productService.delete(id, operationType);
        } catch (Exception e) {
            return e.getMessage();
        }
        return "success";
    }

    @GetMapping("/findById")
    public Product findById (Long id) {
        return productService.findById(id);
    }
}
